<template>
    <v-app>
        <!-- 导航栏 -->
        <cwk-view-navigation ref="cwkViewNavigation"/>

        <cwk-view-app-bar @unDrawer="unDrawer"/>

        <cwk-view-main/>

        <cwk-view-footer/>
    </v-app>
</template>

<script>
    // @ is an alias to /src
    import CwkViewAppBar from '@/views/components/home/AppBar.vue'
    import CwkViewNavigation from '@/views/components/home/Navigation.vue'
    import CwkViewMain from '@/views/components/home/Main.vue'
    import CwkViewFooter from '@/views/components/home/Footer.vue'

    export default {
        name: 'Home',
        components: {
            CwkViewAppBar,
            CwkViewNavigation,
            CwkViewMain,
            CwkViewFooter
        },
        methods: {
            initMenus() {
                // 加载
                if (this.$store.state.routes.length === 0) {
                    this.$axios.get("/menu").then(response => {
                        this.$store.commit('initRoutes', response.data)
                    }).catch(error => {
                        console.log(error);
                    })
                }
            },
            unDrawer() {
                this.$refs.cwkViewNavigation.unDrawer();
            }
        },
        created() {
            this.initMenus();
        }
    }
</script>
